#define ElemType int

#include "common.h"

int* plusOne(int* digits, int digitsSize, int* returnSize);

int main()
{
	return 0;
}

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* plusOne(int* digits, int digitsSize, int* returnSize)
{
	*returnSize = digitsSize;
	for (int i = digitsSize - 1; i >= 0; i--)
		if (digits[i] != 9) {
			++digits[i];
			for (int j = i + 1; j < digitsSize; j++)
				digits[j] = 0;
			return digits;
		}

	free(digits);
	(*returnSize)++;
	int* res = calloc((digitsSize + 1), sizeof(int));
	res[0] = 1;

	return res;
}
